﻿package net.wangit.jdbc.sqltype;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

public class IntegerSqlType extends NullableSqlType implements VersionSqlType {

	private static final long serialVersionUID = 1L;

	public IntegerSqlType() {
	}

	public String get(ResultSet rs, String name) throws SQLException {
		int value = rs.getInt(name);
		if (rs.wasNull())
			return null;
		else
			return Integer.toString(value);
	}

	public void setNotNull(PreparedStatement st, String value, int index)
			throws SQLException {
		if ("".equals(value))
			st.setNull(index, sqlType());
		else
			st.setInt(index, Integer.parseInt(value));
	}

	public int sqlType() {
		return Types.INTEGER;
	}

	public String next(String current) {
		return Integer.toString(Integer.parseInt(current) + 1);
	}

	public String seed() {
		return "0";
	}
}
